/**
 * 文档作者: wj
 * 创建时间：2018年05月04日
 * 修改时间：2018年05月04日
 * 描述信息：我的页面
 */

import React, { Component } from 'react';
import './me.scss';
import Card from '../components/card/card';
import ItemList from '../components/item-list/item-list';
import userModel from '../api/user.model';
import util from '../../util/util';

class Me extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data: void 0
    }
    this.userModel = userModel;
  }

  componentWillMount() {
    util.wxShare();
    if (!userModel.keep) {
      this.userModel.init('me').then(res => {
        this.setState({
          data: res
        })
      })
    }
  }

  render() {
    const userModel = this.userModel
    document.body.style.background = '#f6f5f6';
    return userModel.svcRegWithWx ? <div className="page-me top-center">
    <Card data={userModel.svcRegWithWx.uinfo} onUpgrade={this.onUpgrade.bind(this)}></Card>
      <ItemList data={userModel.svcRegWithWx} onJump={this.onJump.bind(this)}></ItemList>
    </div>: '';
  }

  componentDidMount() {
    util.setTitle('首页');
  }

  /**
   * 单击列表
   * @param {Object} node 节点数据
   */
  onJump(node) {
    if (node.name !== 'interests') {
      this.props.history.push(`/${node.name}`);
    } else {
      window.location.href = 'https://mp.weixin.qq.com/s?__biz=MzAxNTUxMzkwNA==&mid=2650146037&idx=1&sn=5c8387185b2d5aa3c81b95dca43f3613&chksm=838044aab4f7cdbc9f6ea6c2e0eeb988c7c0ad3190c6bd9d0950a775ef2fb6b88cd49c2da335#rd';
    }
  }

  /**
   * 单击升级
   * @memberof Me
   */
  onUpgrade() {
    this.props.history.push(`/certified`);
  }
  
}

export default Me;
